import requests


class UserApi(object):

    @classmethod
    def add_user(cls,headers,body):
        url = "http://ihrm-test.itheima.net/api/sys/user"
        resp = requests.post(url=url,headers=headers,json=body)
        return resp#要返回响应数据

    @classmethod
    def query_user(cls,headers,id):
        url = "http://ihrm-test.itheima.net/api/sys/user/" +id
        resp = requests.get(url=url,headers=headers)
        return resp

    @classmethod
    def modify_user(cls,headers,id,body):
        url = "http://ihrm-test.itheima.net/api/sys/user/"+id
        resp = requests.put(url=url,headers=headers,json=body)
        return resp

    @classmethod
    def delete_user(cls,headers,id):
        url = "http://ihrm-test.itheima.net/api/sys/user/"+id
        resp = requests.delete(url=url,headers=headers)
        return resp


if __name__ == '__main__':
    token = "Bearer "+"6f6aa173-445a-46d4-8aeb-da49cb5fb4eb"
    headers = {"Content-Type": "application/json", "Authorization": token}
    body = {"username": "xiaoxiami001","mobile": "13912344324","workNumber": "000111"}
    resp = UserApi.add_user(headers=headers,body=body)
    print(resp.json())
    #查询
    id = "1520707268574822400"
    UserApi.query_user(headers=headers,id=id)
    # 修改
    modify_body = {"username": "xiaoxiami001", "password": "12345678"}
    resp = UserApi.modify_user(headers=headers,id=id,body=modify_body)
    print(resp.json())
    #删除
    resp = UserApi.delete_user(headers=headers,id=id)
    print(resp.json())


